/**   
* @Title: EventSourceMain.java 
* @Package cn.com.ytst.data.integration.core.channel.event 
* @Description: 测试
* @author 123774135@qq.com 
* @date 2020年6月12日 下午2:11:43 
* @version V1.0   
*/
package cn.com.ytst.data.integration.core.channel.event;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.YieldingWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

/** 
* @ClassName: EventSourceMain 
* @Description: 测试 
* @author 123774135@qq.com 
* @date 2020年6月12日 下午2:11:43 
*  
*/
public class EventSourceMain {

	
	public static void main(String[] args) {
		int buffersize = 2048;
		ExecutorService executorService = Executors.newSingleThreadExecutor();
		// final EventFactory<T> eventFactory,
        //final int ringBufferSize,
        //final ThreadFactory threadFactory,
       // final ProducerType producerType,
       // final WaitStrategy waitStrategy
		ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("Disruptor_-%s").build();
		Disruptor<EventBuilder> disruptor = new Disruptor<>( EventBuilder::new , buffersize,threadFactory,ProducerType.SINGLE,new YieldingWaitStrategy());
		disruptor.handleEventsWith(new EventSourceHander());
		RingBuffer<EventBuilder> ringBuffer = disruptor.start();
		EventSourceProduct eventsourceproduct = new  EventSourceProduct(ringBuffer);
		String line = "“全面建成小康社会，一个少数民族也不能少。”近日，习近平总书记在宁夏考察时，再一次强调了这个重要观点。一个少数民族也不能少”，深情的话语里包含着怎样的深意？中华民族是多元一体的伟大民族早在先秦时期，我国就逐渐形成了以炎黄华夏为凝聚核心、“五方之民”共天下的交融格局。秦国“书同文，车同轨，量同衡，行同伦”，开启了中国统一的多民族国家发展的历程。此后，无论哪个民族入主中原，都以统一天下为己任，都以中华文化的正统自居。";
		for(int i = 0; i < 1000000;i++) {
			eventsourceproduct.put(line);
		}
		
		 disruptor.shutdown();
//		 executorService.shutdown(); // Disable new tasks from being submitted
//	        try {
//	            // Wait a while for existing tasks to terminate
//	            if (!executorService.awaitTermination(60/2, TimeUnit.SECONDS)) {
//	            	executorService.shutdownNow(); // Cancel currently executing tasks
//	                // Wait a while for tasks to respond to being cancelled
//	                if (!executorService.awaitTermination(60/2, TimeUnit.SECONDS))
//	                    System.err.println("Pool did not terminate");
//	            }
//	        } catch (InterruptedException ie) {
//	        	executorService.shutdownNow();
//	            Thread.currentThread().interrupt();
//	        }
	}
}
